home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FishMarket 1.0
/
FishMarket v1.0.iso
/
fishies
/
051-075
/
disk_054
/
ispell
/
term.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-06
|
4KB
|
215 lines
/* -*- Mode:Text -*- */
/*
* term.c - deal with termcap, and unix terminal mode settings
*
* Pace Willisson, 1983
*/
#include <stdio.h>
#ifdef unix
# include <sgtty.h>
#endif
#include <signal.h>
#include "ispell.h"
#ifdef AMIGA
char PC = '\000'; /* padding character */
char *BC = "\033[D"; /* backspace if not ^H */
char *cd = "\033[J"; /* clear to end of display */
char *cl = "\033[H\033[J"; /* clear display */
char *cm = "\033[%i%2;%2H"; /* cursor movement */
char *ho = "\033[H"; /* home */
char *so = "\033[7;30;31m"; /* standout */
char *se = "\033[0;30;31m"; /* standout end */
int li=22; /* lines */
#else
char PC; /* padding character */
char *BC; /* backspace if not ^H */
char *cd; /* clear to end of display */
char *cl; /* clear display */
char *cm; /* cursor movement */
char *ho; /* home */
char *so; /* standout */
char *se; /* standout end */
int li; /* lines */
#endif
char termcap[1024];
char termstr[1024]; /* for string values */
char *termptr;
int erasechar;
int killchar;
char tempfile[200];
extern int putch();
erase ()
{
if (cl)
tputs(cl, li, putch);
else {
if (ho)
tputs(ho, 100, putch);
else if (cm)
tputs(tgoto(cm, 0, 0), 100, putch);
tputs(cd, li, putch);
}
}
move (row, col)
{
tputs (tgoto (cm, col, row), 100, putch);
}
inverse ()
{
tputs (so, 10, putch);
}
normal ()
{
tputs (se, 10, putch);
}
backup ()
{
if (BC)
tputs (BC, 1, putch);
else
putchar ('\b');
}
putch (c)
{
putchar (c);
}
#ifdef unix
struct sgttyb sbuf, osbuf;
#endif
static termchanged = 0;
terminit ()
{
int done();
int tpgrp;
int onstop();
extern short ospeed;
retry:
#ifdef unix
sigsetmask(1<<SIGTSTP | 1<<SIGTTIN | 1<<SIGTTOU);
if (ioctl(0, TIOCGPGRP, &tpgrp) != 0) {
fprintf (stderr, "Can't deal with non interactive use yet.\n");
exit (1);
}
if (tpgrp != getpgrp(0)) { /* not in foreground */
sigsetmask(1<<SIGTSTP | 1<<SIGTTIN);
signal(SIGTTOU, SIG_DFL);
kill(0, SIGTTOU);
/* job stops here waiting for SIGCONT */
goto retry;
}
ioctl (0, TIOCGETP, &osbuf);
termchanged = 1;
sbuf = osbuf;
sbuf.sg_flags &= ~ECHO;
sbuf.sg_flags |= RAW;
ioctl (0, TIOCSETP, &sbuf);
erasechar = sbuf.sg_erase;
killchar = sbuf.sg_kill;
ospeed = sbuf.sg_ospeed;
signal (SIGINT, done);
sigsetmask(0);
signal(SIGTTIN, onstop);
signal(SIGTTOU, onstop);
signal(SIGTSTP, onstop);
tgetent(termcap, getenv("TERM"));
termptr = termstr;
BC = tgetstr("bc", &termptr);
cd = tgetstr("cd", &termptr);
cl = tgetstr("cl", &termptr);
cm = tgetstr("cm", &termptr);
ho = tgetstr("ho", &termptr);
so = tgetstr("so", &termptr); /* inverse video on */
se = tgetstr("se", &termptr); /* inverse video off */
li = tgetnum("li");
#endif
}
done ()
{
unlink (tempfile);
#ifdef unix
if (termchanged)
ioctl (0, TIOCSETP, &osbuf);
#endif
exit (0);
}
#ifdef unix
onstop(signo)
int signo;
{
ioctl (0, TIOCSETP, &osbuf);
signal(signo, SIG_DFL);
kill(0, signo);
/* stop here until continued */
signal(signo, onstop);
ioctl (0, TIOCSETP, &sbuf);
}
#endif
stop ()
{
#ifdef unix
onstop (SIGTSTP);
#else
fprintf (stderr, "sorry -- stop not implemented yet\n");
fflush (stderr);
sleep (2);
#endif
}
shellescape (buf)
char *buf;
{
#ifdef unix
ioctl (0, TIOCSETP, &osbuf);
signal (SIGINT, 1);
signal (SIGQUIT, 1);
signal(SIGTTIN, SIG_DFL);
signal(SIGTTOU, SIG_DFL);
signal(SIGTSTP, SIG_DFL);
#endif
system (buf);
#ifdef unix
signal(SIGTTIN, onstop);
signal(SIGTTOU, onstop);
signal(SIGTSTP, onstop);
signal (SIGINT, done);
signal (SIGQUIT, SIG_DFL);
ioctl (0, TIOCSETP, &sbuf);
#endif
printf ("\n-- Type space to continue --");
getchar ();
}